package com.meishij.customerview;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.meishij.R;

/**
 * Created by Administrator on 2016/10/17.
 * 我是youngKaka 我的心愿是世界和平
 */

public class MainQuitDialog extends Dialog implements View.OnClickListener {
    private View view;

    public void setListener(OnCompleteClick listener) {
        this.listener = listener;
    }

    private OnCompleteClick listener;

    public MainQuitDialog(Context context) {
        super(context);
    }

    public MainQuitDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected MainQuitDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = LayoutInflater.from(getContext()).inflate(R.layout.item_main_exit_dialog_view, null);
        view.findViewById(R.id.tv_main_quit).setOnClickListener(this);
        view.findViewById(R.id.tv_main_continue).setOnClickListener(this);
        setContentView(view);
        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        lp.width = (int) (dm.density * 300);
        lp.height = (int) (dm.density * 125);
        window.setAttributes(lp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_main_continue:
                if (listener != null) {
                    listener.onContinue();
                }
                break;
            case R.id.tv_main_quit:
                if (listener != null) {
                    listener.onQuit();
                }
                break;
        }
    }

    public interface OnCompleteClick {
        void onContinue();

        void onQuit();
    }
}
